package org.otherworld.frame.filebrowser.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

import org.otherworld.frame.filebrowser.tree.FileTreeNode;

public class FileBrowserNew implements ActionListener{
	private JPanel panel;
	private JTree tree;

	public FileBrowserNew(JPanel panel, JTree tree) {
		this.panel = panel;
		this.tree = tree;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		JTree tree = this.tree;
		TreePath path = tree.getSelectionPath();
		FileTreeNode node = (FileTreeNode)path.getLastPathComponent();
		File targetDir = node.getFile();
	    String input = JOptionPane.showInputDialog(null, "Enter File name:", "File name",
	            JOptionPane.WARNING_MESSAGE);
	    File newFile = new File(targetDir+input);
	    if (!newFile.exists()) {
	    	try {
	    		newFile.createNewFile();
	    	} catch (Exception ex) {
	    		ex.printStackTrace();
	    	}
	    }
		tree.updateUI();
		
	}
}
